package com.uinnova.springboot.scheduling;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Scheduled(fixedRate = 5000)上一次执行时间点开始之后5秒在开始执行
 * @Scheduled（fixedDelay = 5000)上一次执行时间点结束后五秒开始执行
 * @Scheduled(initialDelay = 1000,fixRate = 5000):第一次延迟执行一秒，下面按照开始后五秒执行
 * @Scheduled(cron ="")按照cron表达式执行
 */
@Component
public class ScheduledTasks {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Async
    @Scheduled(fixedRate = 50000)
    public void reportCurrentTime(){
        System.out.println("现在时间："+DATE_TIME_FORMATTER.format(LocalDateTime.now()));
    }

    @Async
    @Scheduled(fixedDelay = 80000)
    public void reportCurrentTime1(){
        System.out.println("现在时间1："+DATE_TIME_FORMATTER.format(LocalDateTime.now()));
    }

    @Async
    @Scheduled(initialDelay = 100000,fixedRate = 200000)
    public void reportCurrentTime2(){
        System.out.println("现在时间2:"+DATE_TIME_FORMATTER.format(LocalDateTime.now()));
    }
    @Async
    @Scheduled(cron = "0/1 * * * * ? ")
    public void demoSchedule() {
        System.out.println("现在时间2:"+DATE_TIME_FORMATTER.format(LocalDateTime.now()));
    }





}
